package net.liuyimin.util;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * 分布式锁客户端（工厂类）
 */
@Component
public class DistributedLockClient {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    private String uuid;

    // 无参构造 初始化唯一标识
    public DistributedLockClient() {
        this.uuid = UUID.randomUUID().toString();
    }

    public DistributedRedisLock getRedisLock(String lockName){
        return new DistributedRedisLock(stringRedisTemplate, lockName, uuid);
    }

}
